// API Response Types
export interface ApiResponse<T = any> {
  success: boolean
  data?: T
  error?: {
    code: string
    message: string
    details?: any
  }
  message?: string
}

// User Types
export interface User {
  id: string
  username: string
  email: string
  displayName?: string
  role: 'developer' | 'admin'
  status: 'active' | 'suspended' | 'inactive'
  verified: boolean
  avatar?: string
  bio?: string
  website?: string
  location?: string
  createdAt: string
  updatedAt: string
}

export interface AuthTokens {
  accessToken: string
  refreshToken: string
  expiresIn: number
}

export interface LoginRequest {
  email: string
  password: string
}

export interface RegisterRequest {
  username: string
  email: string
  password: string
  displayName?: string
  subscribeNewsletter?: boolean
}

// Plugin Types
export interface Plugin {
  id: string
  name: string
  displayName: string
  description?: string
  category: string
  tags?: string[]
  keywords?: string[]
  status: 'pending' | 'approved' | 'rejected' | 'suspended'
  visibility?: 'public' | 'private'
  repositoryUrl?: string
  homepageUrl?: string
  documentationUrl?: string
  license?: string
  lastVersion?: string
  latestVersion?: string
  totalDownloads: number
  rating: {
    average: number
    count: number
  }
  verified?: boolean
  featured?: boolean
  developer: {
    username: string
    displayName?: string
    email?: string
    verified: boolean
  }
  createdAt: string
  updatedAt: string
}

export interface PluginVersion {
  id: string
  pluginId: string
  version: string
  changelog?: string
  fileSize: number
  fileHash: string
  downloadUrl: string
  signature?: string
  manifest: Record<string, any>
  createdAt: string
}

export interface PluginStats {
  totalDownloads: number
  weeklyDownloads: number
  monthlyDownloads: number
  downloadHistory: Array<{
    date: string
    downloads: number
  }>
  topVersions: Array<{
    version: string
    downloads: number
    percentage: number
  }>
}

// API Key Types
export interface ApiKey {
  id: string
  name: string
  keyPrefix: string
  permissions: string[]
  lastUsed?: string
  expiresAt?: string
  createdAt: string
  updatedAt: string
}

export interface CreateApiKeyRequest {
  name: string
  permissions: string[]
  expiresAt?: string
}

// Security Types
export interface SecurityScan {
  id: string
  versionId: string
  scanType: 'vulnerability' | 'malware' | 'dependency' | 'code_quality' | 'license'
  status: 'pending' | 'running' | 'completed' | 'failed'
  result: 'pass' | 'warning' | 'fail'
  score: number
  findings: SecurityFinding[]
  startedAt: string
  completedAt?: string
}

export interface SecurityFinding {
  id: string
  type: 'vulnerability' | 'malware' | 'suspicious_code' | 'dependency_issue' | 'license_issue'
  severity: 'low' | 'medium' | 'high' | 'critical'
  title: string
  description: string
  file?: string
  line?: number
  column?: number
  cve?: string
  cwe?: string
  recommendation: string
  references: string[]
}

// Admin Types
export interface AdminStats {
  overview: {
    totalPlugins: number
    totalDevelopers: number
    totalDownloads: number
    pendingReviews: number
  }
  plugins: {
    approved: number
    pending: number
    rejected: number
    suspended: number
  }
  developers: {
    active: number
    suspended: number
    verified: number
  }
  activity: {
    newPluginsThisWeek: number
    newDevelopersThisWeek: number
    downloadsThisWeek: number
  }
}

export interface AuditLog {
  id: string
  action: string
  resourceType: 'plugin' | 'user' | 'api_key'
  resourceId: string
  userId: string
  userEmail: string
  details: Record<string, any>
  ipAddress: string
  userAgent: string
  createdAt: string
}

// Pagination Types
export interface PaginationParams {
  page?: number
  limit?: number
  search?: string
  sortBy?: string
  sortOrder?: 'asc' | 'desc'
}

export interface PaginatedResponse<T> {
  items: T[]
  pagination: {
    page: number
    limit: number
    total: number
    totalPages: number
    hasNext: boolean
    hasPrev: boolean
  }
}

// Plugin-specific paginated response (matches actual API)
export interface PluginPaginatedResponse {
  plugins: Plugin[]
  pagination: {
    page: number
    limit: number
    total: number
    totalPages: number
  }
}

// Filter Types
export interface PluginFilters extends PaginationParams {
  category?: string
  status?: string
  developerId?: string
  tags?: string[]
}

export interface UserFilters extends PaginationParams {
  role?: string
  status?: string
  verified?: boolean
}

// Upload Types
export interface UploadProgress {
  loaded: number
  total: number
  percentage: number
}

export interface FileUploadResponse {
  fileId: string
  fileName: string
  fileSize: number
  fileHash: string
  uploadUrl: string
}
